<?php
/**
 * Created by PhpStorm.
 * User: sundy
 * Date: 2020/2/3
 * Time: 10:11
 */

namespace App\Admin\Controllers;

use Illuminate\Support\Facades\DB;
use Encore\Admin\Controllers\AdminController;
use App\Record;
use Encore\Admin\Grid;

class WaterBillController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '资金流水';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Record);
        $grid->filter(function(Grid\Filter $filter){
            $filter->disableIdFilter();
            $filter->like('vc_product_name', 'Name');
//            $filter->like('nickname', 'User');
            $filter->between('dt_order_time', 'Order Time')->datetime();
        });
        $grid->quickSearch('out_trade_no','vc_account','i_product_id','vc_product_name','openid');
        $grid->i_id('ID')->hide();
        $grid->model()->orderby('dt_order_time','desc');
        $grid->column('dt_order_time', __('Order Time'))->filter('range', 'datetime')->sortable();

        $grid->column('vc_product_name', __('Name'));


        $grid->column('ti_type', __('Type'))->display(function ($type) {
            return $type==1?'<span style="color:blue">充值</span>':'<span style="color:orange">购买</span>';
        })->filter(
            [
                1 => '充值',
                2 => '购买'
            ]
        );
        $grid->column('amount', __('Amount'));

        $grid->disableCreateButton();
        $grid->actions(function ($actions) {
            // 去掉删除
            $actions->disableDelete();
            $actions->disableEdit();
            $actions->disableDetail();
        });
        $grid->tools(function ($tools) {
            $url = config('app.url').'/admin/record';
            $tools->append("<a href=$url class='btn btn-sm btn-success' style='float: right;margin-left: 20px;'>
            <i class='fa fa-save'></i>&nbsp;&nbsp;刷新
            </a>");
            $tools->batch(function ($batch) {
                $batch->disableDelete();
            });
        });
        return $grid;
    }
}
